<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>xeokit Example</title>
    <link href="../css/pageStyle.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
    <style>
        #myNavCubeCanvas {
            position: absolute;
            width: 250px;
            height: 250px;
            bottom: 100px;
            left: 50px;
            z-index: 200000;
        }
    </style>
</head>
<body>
<input type="checkbox" id="info-button"/>
<label for="info-button" class="info-button"><i class="far fa-3x fa-question-circle"></i></label>
<canvas id="myCanvas"></canvas>
<canvas id="myNavCubeCanvas"></canvas>
<div class="slideout-sidebar">
    <img class="info-icon" src="../../assets/images/gltf_logo.png"/>
    <h1>GLTFLoaderPlugin</h1>
    <p>Loading a glTF roadworks scan captured on iPhone 12 Pro with <a href="https://scaniverse.com/">Scaniverse</a></p>
    <h3>Stats</h3>
    <ul>
        <li>
            <div id="time">Loading JavaScript modules...</div>
        </li>
    </ul>
    <h3>Components used</h3>
    <ul>
        <li>
            <a href="../../docs/class/src/viewer/Viewer.js~Viewer.html"
               target="_other">Viewer</a>
        </li>
        <li>
            <a href="../../docs/class/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js~GLTFLoaderPlugin.html"
               target="_other">GLTFLoaderPlugin</a>
        </li>
    </ul>
    <h3>Resources</h3>
    <ul>
        <li>
            <a href="../../assets/models/gltf/Roadworks/license.txt"
               target="_other">Model source</a>
        </li>
    </ul>
</div>
</body>
<script type="module">

    import {Viewer, NavCubePlugin, GLTFLoaderPlugin} from "../../dist/xeokit-sdk.min.es.js";

    const viewer = new Viewer({
        canvasId: "myCanvas",
        transparent: true,
        pbrEnabled: false,
        colorTextureEnabled: true
    });

    new NavCubePlugin(viewer, {
        canvasId: "myNavCubeCanvas",
        color: "lightblue",
        visible: true,         // Initially visible (default)
        cameraFly: true,       // Fly camera to each selected axis/diagonal
        cameraFitFOV: 45,      // How much field-of-view the scene takes once camera has fitted it to view
        cameraFlyDuration: 0.5 // How long (in seconds) camera takes to fly to each new axis/diagonal
    });


    viewer.scene.gammaInput = true;
    viewer.scene.gammaOutput = true;
    viewer.scene.gammaFactor = 2.4;

    viewer.camera.eye = [-3.351107502463288, 3.9321259279903114, 4.030067755126885];
    viewer.camera.look = [-0.687950493700225, 0.9435747389607769, 0.21646512460703526];
    viewer.camera.up = [0.309485261773766, 0.8413154758004762, -0.4431784549404927];

    viewer.cameraControl.doublePickFlyTo = false;

    const gltfLoader = new GLTFLoaderPlugin(viewer);

    const sceneModel = gltfLoader.load({
        id: "myModel",
        src: "../../assets/models/gltf/Roadworks/glTF/scene.gltf"
    });

    const t0 = performance.now();
    document.getElementById("time").innerHTML = "Loading model...";
    sceneModel.on("loaded", function () {
        const t1 = performance.now();
        document.getElementById("time").innerHTML = "Model loaded in " + Math.floor(t1 - t0) / 1000.0 + " seconds<br>Objects: " + sceneModel.numEntities;
    });

    sceneModel.on("loaded", () => {
        viewer.cameraFlight.flyTo(sceneModel);
    });

    viewer.cameraControl.on("picked", function (e) {
        console.log(e.entity.id);
    })

    window.viewer = viewer;    // For debugging

</script>
</html>